package com.xrj4j.car_news.adapter

import android.text.TextUtils
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.squareup.picasso.Picasso
import com.xrj4j.car_news.R

object ImageViewBindingAdapter {


    @BindingAdapter("itemImage") //增加控件绑定属性 app:itemImage
    @JvmStatic //静态方法
    fun setImage(iv: ImageView, url: String) {
        if (TextUtils.isEmpty(url)) {
            iv.setImageResource(R.mipmap.car)
        } else {
            Picasso.get().load(url).placeholder(R.mipmap.car).error(R.mipmap.car).into(iv)
        }
    }
}